package cn.dengta.webapp.risk.bean;

import java.time.Duration;
import java.time.temporal.ChronoUnit;
import javax.annotation.Nullable;

import cn.dengta.common.util.Common;
import lombok.Getter;

/**
 * 风控类型
 *
 * @author XiaoRong
 * @since 2022-05-31
 *
 * https://help.ishumei.com/docs/tj/image/newest/developDoc
 */
@Getter
public enum RiskType {

	/** 文本 数美 **/
	TEXT(1, "text", "https://api-text-xjp.fengkongcloud.com/text/v4", "https://api-text-gz.fengkongcloud.com/text/v4", 1),
	/** 图片 数美 **/
	IMAGE(2, "image", "https://api-img-xjp.fengkongcloud.com/image/v4", "https://api-img-sh.fengkongcloud.com/image/v4", 5),
	/** 多张图片 数美 **/
	MULTI_IMAGE(2, "image", "https://api-img-xjp.fengkongcloud.com/image/v4", "https://api-img-sh.fengkongcloud.com/image/v4", 5),
	/** 音频-语音消息 **/
	AUDIO(3, "audio", "http://api-audio-sh.fengkongcloud.com/v2/saas/anti_fraud/audio", "https://api-audio-sh.fengkongcloud.com/v2/saas/anti_fraud/audio",3),
	/** 语音通话 易盾 **/
	VOICE_STREAM(4, "voiceStream", null, 3),
	/** 视频文件 **/
	VIDEO(5, "video", "https://video-api.fengkongcloud.com/v2/saas/anti_fraud/video", "https://api-video-sh.fengkongcloud.com/v2/saas/anti_fraud/video", 2),
	/** 视频通话 易盾 **/
	VIDEO_STREAM(6, "videoStream", null, 3),
	/** 聊天消息文本 数美 **/
	IM_TEXT(7, "im_text", "https://api-text-xjp.fengkongcloud.com/text/v4", "https://api-text-gz.fengkongcloud.com/text/v4", 1),
	/** 聊天消息图片 数美 **/
	IM_IMAGE(8, "im_image", "https://api-img-xjp.fengkongcloud.com/image/v4", "https://api-img-sh.fengkongcloud.com/image/v4", 5),
	/** 群聊天消息文本 数美 **/
	IM_GROUP_TEXT(9, "im_group_text", "https://api-text-xjp.fengkongcloud.com/text/v4", "https://api-text-gz.fengkongcloud.com/text/v4", 1),
	/** 群聊天消息图片 数美 **/
	IM_GROUP_IMAGE(10, "im_group_image", "https://api-img-xjp.fengkongcloud.com/image/v4", "https://api-img-sh.fengkongcloud.com/image/v4", 5),
	/** 语音通话关闭通知 **/
	CLOSE_AUDIO_STREAM(11, "closeAudioStream", "https://api-audiostream-sh.fengkongcloud.com/v2/saas/anti_fraud/finish_audiostream",
			"https://api-audiostream-sh.fengkongcloud.com/v2/saas/anti_fraud/finish_audiostream",1),
	/** 视频通话关闭通知 **/
	CLOSE_VIDEO_STREAM(12, "closeVideoStream", "https://api-videostream-sh.fengkongcloud.com/v3/saas/anti_fraud/finish_videostream",
			"https://api-videostream-sh.fengkongcloud.com/v3/saas/anti_fraud/finish_videostream",1),
	/** 天网 */
	SKYNET(13, "skynet", "https://api-skynet-xjp.fengkongcloud.com/v4/event", "https://api-skynet-bj.fengkongcloud.com/v4/event", 1),
	/** 语音通话 数美 **/
	AUDIO_SM_STREAM(14, "sm_audioStream", "https://api-audiostream-xjp.fengkongcloud.com/audiostream/v4",
			"https://api-audiostream-sh.fengkongcloud.com/audiostream/v4", 5),
	/** 视频通话 数美 **/
	VIDEO_SM_STREAM(15, "sm_videoStream", "https://api-videostream-xjp.fengkongcloud.com/videostream/v4",
			"https://api-videostream-sh.fengkongcloud.com/videostream/v4", 5),
	/** 1V1不露脸/性别不符/黑屏 **/
	IM_CUSTOM_TYPE(16, "im_custom_type", "", 2),
	/** 关闭视频通话检测 数美 **/
	CLOSE_VIDEO_SM_STREAM(17, "closeSmVideoStream", "https://api-videostream-xjp.fengkongcloud.com/finish_videostream/v4",
			"https://api-videostream-sh.fengkongcloud.com/finish_videostream/v4",2),
	/** 对应 AppSmRiskConfig > text */
	RISK_CLIENT_TEXT(18, "risk_client_text", "", 0),
    /** 对应 AppSmRiskConfig > image */
	RISK_CLIENT_IMAGE(19, "risk_client_image", "", 0),
    /** 对应 AppSmRiskConfig > audio */
	RISK_CLIENT_AUDIO(20, "risk_client_audio", "", 0),
	/** 头像检查开关 */
	RISK_CLIENT_AVATAR(21, "risk_client_avatar", "", 0),

	;

	public final Integer value;
	public final String label;
	/** 请求路径 **/
	public final String url;
	public final String url_cn;
	/** 超时时间(秒) **/
	public final Duration timeout;

	RiskType(Integer value, String label, String url, String url_cn, int timeoutSecs) {
		this.value = value;
		this.label = label;
		this.url = url;
		this.url_cn = url_cn;
		this.timeout = Duration.of(timeoutSecs, ChronoUnit.SECONDS);
	}

	RiskType(Integer value, String label, String url, int timeoutSecs) {
		this(value, label, url, url, timeoutSecs);
	}

	public static final RiskType[] CACHE = values();

	public static RiskType of(@Nullable Integer type) {
		return Common.getEnum(CACHE, RiskType::getValue, type);
	}

}
